package com.hbm.usercenter.fragment;


import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ListView;

import com.hbm.usercenter.adpter.DealOrderAdapter;
import com.hbm.usercenter.base.BaseFragment;
import com.hbm.usercenter.base.LoadingPager;
import com.hbm.usercenter.base.LoadingPager.LoadedResult;
import com.hbm.usercenter.bean.OrderBean;
import com.hbm.usercenter.factory.ListViewFactory;
import com.hbm.usercenter.protocol.OrderToPayProtocol;
import com.hbm.usercenter.utils.LogUtils;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class OrderToPayFragment extends BaseFragment {

    protected OrderToPayProtocol mProtocol;
    protected List<OrderBean.RowsBean> mDatas;

    @Override
    protected LoadingPager.LoadedResult initData() {
        mProtocol = new OrderToPayProtocol();
        try {
            OrderBean orderBean = mProtocol.loadData(1);
            LogUtils.s("orderToPayFragment----" + orderBean.toString());
            LoadedResult checkState = checkState(orderBean);
            checkState = checkState(orderBean.rows);
            if (checkState != LoadedResult.SUCCESS) {
                return checkState;
            }
            mDatas = orderBean.rows;

            return LoadedResult.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return LoadedResult.ERROR;
        }
    }

    @Override
    protected View initSuccessView() {
        ListView listView = ListViewFactory.createListView();
        listView.setAdapter(new ToPayAdapter(listView, mDatas));
        return listView;
    }
    class ToPayAdapter extends DealOrderAdapter {

        public ToPayAdapter(AbsListView absListView, List<OrderBean.RowsBean> datas) {
            super(absListView, datas);
        }
    }
}
